
package com.bp;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import javax.swing.JOptionPane;

/**
 *
 * @author Andhini
 */
public class Pemesan extends Paket{
   public String id_pemesan;
   public String nama_pemesan;
   public String alamat_pemesan;
   private String no_telp_pemesan;
   public String email_pemesan;
   public String keberangkatan;
   public int jumalah_wisatawan;

    /**
     * @return the id_pemesan
     */
    public String getId_pemesan() {
        return id_pemesan;
    }

    /**
     * @param id_pemesan the id_pemesan to set
     */
    public void setId_pemesan(String id_pemesan) {
        this.id_pemesan = id_pemesan;
    }

    /**
     * @return the id_biro
     */
    public String getnama_paket() {
        return nama_paket;
    }

    /**
     * @param id_biro the id_biro to set
     */
    public void setNamaPaket(String nama_paket) {
        this.nama_paket = nama_paket;
    }

    /**
     * @return the id_paket
     */
    public String getId_paket() {
        return id_paket;
    }

    /**
     * @param id_paket the id_paket to set
     */
    public void setId_paket(String id_paket) {
        this.id_paket = id_paket;
    }

    /**
     * @return the nama_pemesan
     */
    public String getNama_pemesan() {
        return nama_pemesan;
    }

    /**
     * @param nama_pemesan the nama_pemesan to set
     */
    public void setNama_pemesan(String nama_pemesan) {
        this.nama_pemesan = nama_pemesan;
    }

    /**
     * @return the alamat_pemesan
     */
    public String getAlamat_pemesan() {
        return alamat_pemesan;
    }

    /**
     * @param alamat_pemesan the alamat_pemesan to set
     */
    public void setAlamat_pemesan(String alamat_pemesan) {
        this.alamat_pemesan = alamat_pemesan;
    }

    /**
     * @return the email_pemesan
     */
    public String getEmail_pemesan() {
        return email_pemesan;
    }

    /**
     * @param email_pemesan the email_pemesan to set
     */
    public void setEmail_pemesan(String email_pemesan) {
        this.email_pemesan = email_pemesan;
    }
    /**
     * @return the keberangkatan
     */
    public String getKeberangkatan() {
        return keberangkatan;
    }

    /**
     * @param keberangkatan the keberangkatan to set
     */
    public void setKeberangkatan(String keberangkatan) {
        this.keberangkatan = keberangkatan;
    }

    /**
     * @return the jumalah_wisatawan
     */
    public int getJumalah_wisatawan() {
        return jumalah_wisatawan;
    }

    /**
     * @param jumalah_wisatawan the jumalah_wisatawan to set
     */
    public void setJumalah_wisatawan(int jumalah_wisatawan) {
        this.jumalah_wisatawan = jumalah_wisatawan;
    }

    /**
     * @return the no_telp_pemesan
     */
    public String getNo_telp_pemesan() {
        return no_telp_pemesan;
    }

    /**
     * @param no_telp_pemesan the no_telp_pemesan to set
     */
    public void setNo_telp_pemesan(String no_telp_pemesan) {
        this.no_telp_pemesan = no_telp_pemesan;
    }
    
    
     public void insertPesanan() {
        try {
            Connection connection = new DbBean().getKoneksi();
            Statement s = connection.createStatement();
            String sql = "insert into PESANAN values('" + id_pemesan+ "','" + nama_pemesan+ "','" + alamat_pemesan + "','" +jumalah_wisatawan+ "','"  + no_telp_pemesan + "','" + email_pemesan + "','" + id_paket + "','" + nama_paket + "'," + harga_paket + ",'" + keberangkatan + "',0)";
            ResultSet rs = s.executeQuery(sql);
            JOptionPane.showMessageDialog(null, "data pesanan berhasil dipesan");
            rs.close();
            s.close();
            connection.close();
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "data paket gagal dipesan");
        }
    }
     
     public final String getKode_Pesanan() {
        try {
//            String sql = "select ID_PAKET from IDPAKET desc";
            String sql = "select Id_Pemesan from ID_PEMESAN";
            Connection con = new DbBean().getKoneksi();
            java.sql.Statement sta = con.createStatement();
            ResultSet rs = sta.executeQuery(sql);

            rs.next();


            String result = rs.getString(1);
            int no = Integer.parseInt(result);
            no++;
            sql = "" + no;
            while (sql.length() <= 3) {
                sql = "0" + sql;
            }

            sql = "update Id_Pemesan set ID_PEMESAN = '" + sql + "'";
            sta = con.createStatement();
            sta.executeUpdate(sql);
            con.close();

            return result;


        } catch (SQLException ex) {
            return "";
        }
    }
}
